<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3_3_1-2-限流的工具方法</title>
</head>

<body>


  <!--载入vue.js-->
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

  <div id="Application">
    点击一次，两秒后可获取时间
    <button @click="n_click">按钮</button>
  </div>

  <script>
    //定义组件
    var throttle = false;
    function throttleTool(callback, timeout) {
      if (!throttle) {
        callback();
      } else {
        return;
      }
      throttle = true;
      setTimeout(() => {
        throttle = false;
      }, timeout);
    }

    const App = {
      //组件的方法
      methods: {
        //自做限流函数
        n_click() {
          throttleTool(() => {
            console.log(Date());
          }, 2000);
        },
      },
    };

    Vue.createApp(App).mount("#Application");
  </script>
</body>

</html>